package nc.ui.zzjs.ze03;

import java.awt.Container;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import nc.ui.trade.bsdelegate.BusinessDelegator;
import nc.ui.trade.business.HYPubBO_Client;
import nc.vo.pub.SuperVO;
import nc.vo.zzjs.pub.crowno.sort.CrownoSort;

public class ClientBusinessDelegator extends BusinessDelegator {
	
	@SuppressWarnings("unused")
	private Container parent = null;
	
	public ClientBusinessDelegator(Container parent ){
		this.parent = parent;
	}
	@SuppressWarnings("unchecked")
	@Override
	public SuperVO[] queryHeadAllData(Class headClass, String strBillType,
			String strWhere) throws Exception {	
		return super.queryHeadAllData(headClass, strBillType, strWhere);
	}
	
    public nc.vo.pub.CircularlyAccessibleValueObject[] queryBodyAllData(
            Class voClass, String billType, String key, String strWhere)
            throws Exception {
        SuperVO vo = (SuperVO) voClass.newInstance();
        String strSql = null;
        if (vo.getParentPKFieldName() != null)
            strSql = "(" + vo.getParentPKFieldName() + "='" + key + "')";
        if (strWhere != null && strWhere.length() != 0)
            if (strSql != null)
                strSql = (strWhere) + " and " + strSql;
            else
                strSql = strWhere;
        SuperVO[] vos = (SuperVO[])HYPubBO_Client.queryByCondition(voClass, strSql);
		if (vos != null && vos.length>0) {
			List<SuperVO> list = Arrays.asList(vos);
			CrownoSort sort = new CrownoSort("crowno");
			Collections.sort(list, sort);
			SuperVO[] v = (SuperVO[])Array.newInstance(vos[0].getClass(), list.size());
			return list.toArray(v);
		}else{
			return null;
		}
    }
}
